﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using PKSoftManagement;
using BusinessLogicLayer;
using DataTransferObject;
using DataAccessLayer;

namespace PKSoftManagement
{
    public partial class FrmMain : Office2007RibbonForm
    {
        public FrmMain()
        {
            InitializeComponent();
            this.IsMdiContainer = true;
            TabItem Tab = TabMain.CreateTab("Tiếp nhận bệnh nhân");
            UserControl frm = new TiepNhanKH();
            frm.Dock = DockStyle.Fill;
            Tab.AttachedControl.Controls.Add(frm);
            frm.Show();
            TabMain.SelectedTabIndex = TabMain.Tabs.Count - 1;
        }
        private void danhMucCon_Click(object sender, EventArgs e)
        {
            if (KiemTraTenTabConTrol(((ButtonItem)sender).Text) == false)
            {
                TabItem Tab = TabMain.CreateTab(((ButtonItem)sender).Text);
                UserControl frm = new UserControl();
                switch (((ButtonItem)sender).Name)
                {
                    case "loaiDVTinh": frm = new FormDanhMuc(new LoaiDVTinhBLL()); break;
                    case "dmNhaCungCap": frm = new FormDanhMuc(new NhaCCBLL()); break;
                    case "tiepNhanBenhNhan": frm = new TiepNhanKH(); break;
                    case "hoSoBenhNhan": frm = new FormDanhMuc(new HoSoBenhNhanBLL()); break;
                }
                //  frm.TopLevel = false;
                frm.Dock = DockStyle.Fill;
                Tab.AttachedControl.Controls.Add(frm);
                frm.Show();
                TabMain.SelectedTabIndex = TabMain.Tabs.Count - 1;
            }
        }
        private void TabMain_TabItemClose(object sender, TabStripActionEventArgs e)
        {
            TabItem selectedTab = TabMain.SelectedTab;
            if (MessageBox.Show("Bạn có muốn xóa:" + selectedTab.Text, "Xác nhận", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                TabMain.Tabs.Remove(selectedTab);
            }

        }

        private bool KiemTraTenTabConTrol(string name)
        {
            for (int i = 0; i < TabMain.Tabs.Count; i++)
            {
                if (TabMain.Tabs[i].Text == name)
                {
                    TabMain.SelectedTabIndex = i;
                    return true;
                }
            }
            return false;
        }
    }
}
